package org.hhchat.hiloCoder.code52;

import java.util.*;

/**
 * Created this one by huminghao on 2018/3/25.
 * https://hihocoder.com/problemset/solution/1299183
 */
public class P2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        boolean[][] a = new boolean[n][m];
        String input;
        for (int i = 0; i < n; i++) {
            input = scanner.next();
            char[] chars = input.toCharArray();
            for (int j = 0; j < chars.length; j++) {
                a[i][j] = chars[j] == '1';
            }
        }
        long result = dfs(a);
        System.out.println(result);
    }

    static int n;
    static int m;
    static Map<Integer, Long> vis = new HashMap<>();

    public static long dfs(boolean[][] a) {
        int hasha = arrayToInt(a);
        if (vis.get(hasha) != null) {
            return vis.get(hasha);
        }
        boolean flags = false;
        long result = 0;
        for (int k = 0; k < n * m; k++) {
            int i = k / m;
            int j = k % m;
            if (!a[i][j] && judge(a, i, j)) {
                a[i][j] = true;
                result += dfs(a);
                a[i][j] = false;
                flags = true;
            }
        }
        // 没有可以点亮的，只有1了
        if (!flags) {
            result = 1;
        }
        vis.put(hasha, result);
        return result;
    }

    public static boolean judge(boolean[][] a, int i, int j) {
        if (i - 1 >= 0 && a[i - 1][j]) return true;
        if (i + 1 < n && a[i + 1][j]) return true;
        if (j - 1 >= 0 && a[i][j - 1]) return true;
        if (j + 1 < m && a[i][j + 1]) return true;
        return false;
    }

    static int arrayToInt(boolean[][] a) {
        int res = 0;
        for (boolean[] anA : a) {
            for (int j = 0; j < a[0].length; j++) {
                res = res * 2 + (anA[j] ? 1 : 0);
            }
        }
        return res;
    }

}
